home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / basics / qtmovietrack / common files / comframework.c next >
Encoding:
Text File  |  2000-09-28  |  54.0 KB  |  1,973 lines

  1. //////////
  2. //
  3. //    File:        ComFramework.c
  4. //
  5. //    Contains:    Code for the QuickTime sample code framework that is common to both Macintosh and Windows.
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on the QTShell code written by Tim Monroe, which in turn was based on the MovieShell
  9. //                code written by Kent Sandvik (Apple DTS). This current version is now very far removed from
  10. //                MovieShell.
  11. //
  12. //    Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  13. //
  14. //    Change History (most recent first):
  15. //       
  16. //       <16>         03/15/00    rtm        modified QTFrame_SaveAsMovieFile to create a single-fork, self-contained,
  17. //                                    interleaved, Fast Start movie
  18. //       <15>         03/02/00    rtm        made changes to get things running under CarbonLib
  19. //       <14>         02/16/00    rtm        added QTFrame_GetWindowPtrFromWindowReference
  20. //       <13>         01/19/00    rtm        revised QTFrame_IsAppWindow (dialog windows no longer count as application
  21. //                                    windows); added QTFrame_BuildFileTypeList and QTFrame_AddComponentFileTypes
  22. //                                    to avoid calling GetMovieImporterForDataRef in QTFrame_FilterFiles; removed
  23. //                                    the hard-coded file types
  24. //       <12>         01/14/00    rtm        added support for graphics files, using graphics importers
  25. //       <11>         12/28/99    rtm        added QTFrame_ConvertMacToWinRect and QTFrame_ConvertWinToMacRect
  26. //       <10>         12/21/99    rtm        hard-coded some file types into QTFrame_FilterFiles; if we let QuickTime
  27. //                                    to do all the testing (using GetMovieImporterForDataRef), it takes too long
  28. //       <9>         12/17/99    rtm        added some code to QTFrame_SetMenuItemState to work around a problem that
  29. //                                    appears under MacOS 8.5.1 (as far as I can tell...)
  30. //       <8>         12/16/99    rtm        added QTApp_HandleMenu calls to _HandleFileMenuItem and _HandleEditMenuItem
  31. //                                    to allow the application-specific code to intercept menu item selections;
  32. //                                    added QTFrame_FilterFiles
  33. //       <7>         12/15/99    rtm        added QTApp_Idle call to QTFrame_IdleMovieWindows
  34. //       <6>         12/11/99    rtm        added GetMenuState call to Windows portion of QTFrame_SetMenuItemLabel;
  35. //                                    tweaked _SizeWindowToMovie to guard against NULL movie and/or controller
  36. //       <5>         11/30/99    rtm        added QTFrame_CloseMovieWindows
  37. //       <4>         11/27/99    rtm        added QTFrame_GetFileFilterUPP
  38. //       <3>         11/17/99    rtm        finished support for Navigation Services; added QTFrame_IdleMovieWindows
  39. //       <2>         11/16/99    rtm        begun support for Navigation Services
  40. //       <1>         11/05/99    rtm        first file
  41. //
  42. //    This file contains several kinds of functions: (1) functions that use completely cross-platform APIs and
  43. //    which therefore can be compiled and run for both Mac and Windows platforms with no changes whatsoever (a
  44. //    good example of this is QTFrame_SaveAsMovieFile); (2) functions that are substantially the same on both
  45. //    platforms but which require several short platform-dependent #ifdef TARGET_OS_ blocks (a good example of
  46. //    this is QTFrame_AdjustMenus); (3) functions that retrieve data from framework-specific data structures (a
  47. //    good example of this is QTFrame_GetWindowObjectFromWindow); (4) functions that provide a platform-neutral
  48. //    interface to platform-specific operations (a good example of this is QTFrame_Beep). In a nutshell, this
  49. //    file attempts to provide platform-independent services to its callers, typically functions in the files
  50. //    MacFramework.c, WinFramework.c, and ComApplication.c.
  51. //
  52. //    In general, you should not need to modify this file. Your application-specific code should usually be put
  53. //    into the file ComApplication.c.
  54. //
  55. //////////
  56.  
  57. //////////
  58. //
  59. // header files
  60. //
  61. //////////
  62.  
  63. #include "ComFramework.h"
  64.  
  65.  
  66. //////////
  67. //
  68. // global variables
  69. //
  70. //////////
  71.  
  72. Rect                    gMCResizeBounds;                        // maximum size for any movie window
  73. OSType                     *gValidFileTypes = NULL;                // the list of file types that our application can open
  74.  
  75. #if TARGET_OS_WIN32
  76. extern HWND                ghWnd;
  77. extern HWND                ghWndMDIClient;
  78. extern BOOL                gWeAreSizingWindow;
  79. #endif
  80.  
  81. #if TARGET_OS_MAC
  82. extern Str255            gAppName;
  83. void                    QTFrame_HandleEvent (EventRecord *theEvent);
  84. #endif
  85.  
  86.  
  87. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  88. //
  89. // Menu-handling functions.
  90. //
  91. // Use these functions to handle items in the File and Edit menus.
  92. //
  93. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  94.  
  95. //////////
  96. //
  97. // QTFrame_HandleFileMenuItem
  98. // Handle the specified File menu item.
  99. //
  100. //////////
  101.  
  102. void QTFrame_HandleFileMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  103. {
  104.     // give the application-specific code a chance to intercept the menu item selection
  105.     if (QTApp_HandleMenu(theMenuItem))
  106.         return;
  107.         
  108.     switch (theMenuItem) {
  109.     
  110.         case IDM_FILENEW:
  111.             QTFrame_CreateNewMovie();
  112.             break;
  113.  
  114.         case IDM_FILEOPEN:
  115.             QTFrame_OpenMovieInWindow(NULL, NULL);
  116.             break;
  117.  
  118.         case IDM_FILECLOSE:
  119.             QTFrame_DestroyMovieWindow(theWindow);
  120.             break;
  121.  
  122.         case IDM_FILESAVE:
  123.             QTFrame_UpdateMovieFile(theWindow);
  124.             break;
  125.  
  126.         case IDM_FILESAVEAS:
  127.             QTFrame_SaveAsMovieFile(theWindow);
  128.             break;
  129.             
  130.         case IDM_EXIT:
  131.             QTFrame_QuitFramework();
  132.             break;
  133.  
  134.         default:
  135.             break;
  136.     } // switch (theMenuItem)
  137.     
  138. }
  139.  
  140.  
  141. //////////
  142. //
  143. // QTFrame_HandleEditMenuItem
  144. // Perform the specified edit operation on the specified window.
  145. //
  146. //////////
  147.  
  148. void QTFrame_HandleEditMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  149. {
  150.     WindowObject        myWindowObject = NULL;
  151.     MovieController     myMC = NULL;
  152.     Movie                 myEditMovie = NULL;                // the movie created by some editing operations
  153.     
  154.     // give the application-specific code a chance to intercept the menu item selection
  155.     if (QTApp_HandleMenu(theMenuItem))
  156.         return;
  157.     
  158.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  159.     myMC = QTFrame_GetMCFromWindow(theWindow);
  160.     
  161.     // make sure we have a valid movie controller and a valid window object
  162.     if ((myMC == NULL) || (myWindowObject == NULL))
  163.         return;
  164.  
  165.     switch (theMenuItem) {
  166.     
  167.         case IDM_EDITUNDO:
  168.             MCUndo(myMC);
  169.             (**myWindowObject).fIsDirty = true;
  170.             break;
  171.  
  172.         case IDM_EDITCUT:
  173.             myEditMovie = MCCut(myMC);
  174.             (**myWindowObject).fIsDirty = true;
  175.             break;
  176.  
  177.         case IDM_EDITCOPY:
  178.             myEditMovie = MCCopy(myMC);
  179.             break;
  180.  
  181.         case IDM_EDITPASTE:
  182.             MCPaste(myMC, NULL);
  183.             (**myWindowObject).fIsDirty = true;
  184.             break;
  185.  
  186.         case IDM_EDITCLEAR:
  187.             MCClear(myMC);
  188.             (**myWindowObject).fIsDirty = true;
  189.             break;
  190.             
  191.         case IDM_EDITSELECTALL:
  192.             QTUtils_SelectAllMovie(myMC);
  193.             break;
  194.  
  195.         case IDM_EDITSELECTNONE:
  196.             QTUtils_SelectNoneMovie(myMC);
  197.             break;
  198.  
  199.         default:
  200.             break;
  201.     } // switch (theMenuItem)
  202.     
  203.     // place any cut or copied movie segment onto the scrap
  204.     if (myEditMovie != NULL) {
  205.         PutMovieOnScrap(myEditMovie, 0L);
  206.         DisposeMovie(myEditMovie);
  207.     }
  208. }
  209.  
  210.  
  211. //////////
  212. //
  213. // QTFrame_AdjustMenus 
  214. // Adjust the application's menus.
  215. //
  216. // On Windows, the theWindow parameter is a handle to the active MDI *child* window, if any.
  217. // On Mac, the theWindow parameter is a pointer to the frontmost window, if any.
  218. //
  219. //////////
  220.  
  221. int QTFrame_AdjustMenus (WindowReference theWindow, MenuReference theMenu)
  222. {
  223. #if TARGET_OS_MAC
  224. #pragma unused(theMenu)
  225. #endif
  226.  
  227.     WindowObject        myWindowObject = NULL; 
  228.     MovieController     myMC = NULL;
  229.     MenuReference        myMenu = NULL;
  230.     
  231. #if TARGET_OS_WIN32
  232.     myMenu = theMenu;
  233. #endif
  234.  
  235.     if (theWindow != NULL)
  236.         myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  237.  
  238.     if (myWindowObject != NULL)
  239.         myMC = (**myWindowObject).fController;
  240.  
  241.     //////////
  242.     //
  243.     // configure the Edit menu
  244.     //
  245.     //////////
  246.     
  247. #if TARGET_OS_MAC
  248.     myMenu = GetMenuHandle(kEditMenuResID);
  249. #endif
  250.     if (myMC != NULL) {
  251.         long    myFlags;
  252.         
  253.         MCGetControllerInfo(myMC, &myFlags);
  254.     
  255.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, myFlags & mcInfoUndoAvailable ? kEnableMenuItem : kDisableMenuItem);
  256.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, myFlags & mcInfoCutAvailable ? kEnableMenuItem : kDisableMenuItem);
  257.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, myFlags & mcInfoCopyAvailable ? kEnableMenuItem : kDisableMenuItem);
  258.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, myFlags & mcInfoPasteAvailable ? kEnableMenuItem : kDisableMenuItem);
  259.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, myFlags & mcInfoClearAvailable ? kEnableMenuItem : kDisableMenuItem);
  260.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  261.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  262.     } else {
  263.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, kDisableMenuItem);
  264.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, kDisableMenuItem);
  265.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, kDisableMenuItem);
  266.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, kDisableMenuItem);
  267.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, kDisableMenuItem);
  268.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, kDisableMenuItem);
  269.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, kDisableMenuItem);
  270.     }
  271.  
  272.     //////////
  273.     //
  274.     // configure the File menu
  275.     //
  276.     //////////
  277.     
  278. #if TARGET_OS_MAC
  279.     myMenu = GetMenuHandle(kFileMenuResID);
  280. #endif
  281.     if (theWindow != NULL) {                // there is a window open
  282.         // handle the Close command
  283.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kEnableMenuItem);
  284.         
  285.         // handle the Save As and Save commands
  286.         if (myWindowObject != NULL) {
  287.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kEnableMenuItem);
  288.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, (**myWindowObject).fIsDirty ? kEnableMenuItem : kDisableMenuItem);
  289.         } else {
  290.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  291.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  292.         }
  293.     
  294.     } else {                                // there is no window open    
  295.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  296.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  297.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kDisableMenuItem);        
  298.     }
  299.  
  300.     // adjust any application-specific menus
  301.     QTApp_AdjustMenus(theWindow, theMenu);
  302.  
  303.     return(0);
  304. }
  305.  
  306.  
  307. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  308. //
  309. // Movie-handling functions.
  310. //
  311. // Use these functions to create new movies, open existing movies, save movies, and so forth.
  312. //
  313. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  314.  
  315. //////////
  316. //
  317. // QTFrame_CreateNewMovie
  318. // Create a new movie in a window; returns true if successful.
  319. //
  320. // NOTE: There are several user interface issues that are blissfully ignored by this routine,
  321. // principally the preferred names and the on-screen locations of the new windows. 
  322. //
  323. //////////
  324.  
  325. Boolean QTFrame_CreateNewMovie (void)
  326. {
  327.     Movie                myMovie = NULL;
  328.     FSSpec                myFSSpec;
  329.     StringPtr             myName = QTUtils_ConvertCToPascalString(kNewMovieName);
  330.     
  331.     myMovie = NewMovie(newMovieActive);
  332.     if (myMovie == NULL)
  333.         return(false);
  334.     
  335.     // create a default FSSpec
  336.     FSMakeFSSpec(0, 0L, myName, &myFSSpec);
  337.     
  338.     free(myName);
  339.     
  340.     return(QTFrame_OpenMovieInWindow(myMovie, &myFSSpec));
  341. }
  342.  
  343.  
  344. //////////
  345. //
  346. // QTFrame_OpenMovieInWindow
  347. // Open a movie in a new movie window; return true if successful.
  348. //
  349. // This function is called from several places in our framework. The following combinations are possible:
  350. //    * theMovie == NULL, theFSSpec == NULL: no movie, no file; elicit a movie file from user and open it
  351. //    * theMovie != NULL, theFSSpec == NULL: new movie, no file (yet)
  352. //    * theMovie == NULL, theFSSpec != NULL: no movie, but we have an FSSpec; so just open the specified movie file
  353. //    * theMovie != NULL, theFSSpec != NULL: new movie, theFSSpec contains (at least) the movie name
  354. //
  355. //////////
  356.  
  357. Boolean QTFrame_OpenMovieInWindow (Movie theMovie, FSSpec *theFSSpec)
  358. {
  359.     WindowObject            myWindowObject = NULL;
  360.     Movie                    myMovie = NULL;
  361.     MovieController            myMC = NULL;
  362.     GraphicsImportComponent    myImporter = NULL;
  363.     WindowReference            myWindow = NULL;
  364.     FSSpec                    myFSSpec;
  365.     short                    myRefNum = kInvalidFileRefNum;
  366.     short                    myResID = 0;
  367.     OSType                     myTypeList[] = {kQTFileTypeMovie, kQTFileTypeQuickTimeImage};
  368.     short                    myNumTypes = 2;
  369.     GrafPtr                    mySavedPort;
  370.     Rect                    myRect = {0, 0, 0, 0};
  371.     Point                    myPoint;
  372.     QTFrameFileFilterUPP    myFileFilterUPP = NULL;
  373.     OSErr                    myErr = noErr;
  374.  
  375. #if TARGET_OS_MAC
  376.     myNumTypes = 0;
  377. #endif
  378.  
  379.     // get the current port; we may need to restore it if we cannot successfully create a new window
  380.     GetPort(&mySavedPort);
  381.     
  382.     // if we got neither a movie nor an FSSpec passed in, prompt the user for a movie file
  383.     if ((theMovie == NULL) && (theFSSpec == NULL)) {
  384.         myFileFilterUPP = QTFrame_GetFileFilterUPP((ProcPtr)QTFrame_FilterFiles);
  385.     
  386.         myErr = QTFrame_GetOneFileWithPreview(myNumTypes, (QTFrameTypeListPtr)myTypeList, &myFSSpec, myFileFilterUPP);
  387.     
  388.         if (myFileFilterUPP != NULL)
  389.             DisposeNavObjectFilterUPP(myFileFilterUPP);
  390.  
  391.         if (myErr != noErr)
  392.             goto bail;
  393.     }
  394.     
  395.     // if we got an FSSpec passed in, copy it into myFSSpec
  396.     if (theFSSpec != NULL) {
  397.         FSMakeFSSpec(theFSSpec->vRefNum, theFSSpec->parID, theFSSpec->name, &myFSSpec);        
  398.     }
  399.  
  400.     // if we got no movie passed in, read one from the specified file
  401.     if (theMovie == NULL) {
  402.         // see if the FSSpec picks out an image file; if so, skip the movie-opening code
  403.         myErr = GetGraphicsImporterForFile(&myFSSpec, &myImporter);
  404.         if (myImporter != NULL)
  405.             goto gotImageFile;
  406.             
  407.         // ideally, we'd like read and write permission, but we'll settle for read-only permission
  408.         myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdWrPerm);
  409.         if (myErr != noErr)
  410.             myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdPerm);
  411.  
  412.         // if we couldn't open the file with even just read-only permission, bail....
  413.         if (myErr != noErr)
  414.             goto bail;
  415.  
  416.         // now fetch the first movie from the file
  417.         myResID = 0;
  418.         myErr = NewMovieFromFile(&myMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);
  419.         if (myErr != noErr)
  420.             goto bail;
  421.     } else {
  422.         myMovie = theMovie;
  423.     }
  424.  
  425.     //////////
  426.     //
  427.     // at this point, myMovie is an open movie, but myFSSpec may or may not be a valid FSSpec
  428.     //
  429.     //////////
  430.     
  431.     // set the default progress procedure for the movie
  432.     SetMovieProgressProc(myMovie, (MovieProgressUPP)-1, 0);
  433.         
  434. gotImageFile:
  435.     // create a new window to display the movie in
  436.     myWindow = QTFrame_CreateMovieWindow();
  437.     if (myWindow == NULL)
  438.         goto bail;
  439.     
  440.     myWindowObject = QTFrame_GetWindowObjectFromWindow(myWindow);
  441.     if (myWindowObject == NULL)
  442.         goto bail;
  443.     
  444.     // set the window title
  445.     QTFrame_SetWindowTitleFromFSSpec(myWindow, &myFSSpec, true);
  446.  
  447.     // make sure the movie or image file uses the window GWorld
  448.     if (myMovie != NULL)
  449.         SetMovieGWorld(myMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference(myWindow), NULL);
  450.  
  451.     if (myImporter != NULL)
  452.         GraphicsImportSetGWorld(myImporter, (CGrafPtr)QTFrame_GetPortFromWindowReference(myWindow), NULL);
  453.  
  454.     // create and configure the movie controller
  455.     myMC = QTFrame_SetupController(myMovie, myWindow, true);
  456.         
  457.     // store movie info in the window record
  458.     (**myWindowObject).fMovie = myMovie;
  459.     (**myWindowObject).fController = myMC;
  460.     (**myWindowObject).fGraphicsImporter = myImporter;
  461.     (**myWindowObject).fFileResID = myResID;
  462.     (**myWindowObject).fFileRefNum = myRefNum;
  463.     (**myWindowObject).fCanResizeWindow = true;
  464.     (**myWindowObject).fIsDirty = false;
  465.     (**myWindowObject).fIsQTVRMovie = QTUtils_IsQTVRMovie(myMovie);
  466.     (**myWindowObject).fInstance = NULL;
  467.     (**myWindowObject).fAppData = NULL;
  468.     (**myWindowObject).fFileFSSpec = myFSSpec;
  469.     
  470.     // do any application-specific window object initialization
  471.     QTApp_SetupWindowObject(myWindowObject);
  472.     
  473.     // size the window to fit the movie and controller
  474.     QTFrame_SizeWindowToMovie(myWindowObject);
  475.  
  476.     // set the movie's play hints to allow dynamic resizing
  477.     SetMoviePlayHints(myMovie, hintsAllowDynamicResize, hintsAllowDynamicResize);
  478.  
  479.     // set the movie's position, if it has a 'WLOC' user data atom
  480.     myErr = QTUtils_GetWindowPositionFromFile(myMovie, &myPoint);
  481.  
  482.     // show the window
  483. #if TARGET_OS_MAC
  484.     MoveWindow(myWindow, myPoint.h, myPoint.v, false);
  485.     ShowWindow(myWindow);
  486.     SelectWindow(myWindow);                                // make it front-most, since it's just been created
  487.     InvalWindowRect(myWindow, GetWindowPortBounds(myWindow, &myRect));
  488. #endif
  489. #if TARGET_OS_WIN32
  490.     SetWindowPos(myWindow, 0, myPoint.h, myPoint.v, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  491.     ShowWindow(myWindow, SW_SHOW);
  492.     UpdateWindow(myWindow);
  493. #endif
  494.  
  495.     // if the movie is a streamed movie, then start it playing immediately
  496.     if (QTUtils_IsStreamedMovie(myMovie))
  497.         MCDoAction(myMC, mcActionPrerollAndPlay, (void *)GetMoviePreferredRate(myMovie));
  498.         
  499.     return(true);
  500.     
  501. bail:
  502.     if (myWindow != NULL)
  503. #if TARGET_OS_MAC
  504.         DisposeWindow(myWindow);
  505. #endif
  506. #if TARGET_OS_WIN32
  507.         SendMessage(ghWndMDIClient, WM_MDIDESTROY, (WPARAM)myWindow, 0L);
  508. #endif
  509.         
  510.     if (myMC != NULL)
  511.         DisposeMovieController(myMC);
  512.         
  513.     if (myMovie != NULL)
  514.         DisposeMovie(myMovie);
  515.         
  516.     if (myRefNum != 0)
  517.         CloseMovieFile(myRefNum);
  518.  
  519.     if (myImporter != NULL)
  520.         CloseComponent(myImporter);
  521.         
  522.     MacSetPort(mySavedPort);    // restore the port that was active when this function was called
  523.  
  524.     return(false);
  525. }
  526.  
  527.  
  528. //////////
  529. //
  530. // QTFrame_SetupController
  531. // Create and configure the movie controller.
  532. //
  533. //////////
  534.  
  535. MovieController QTFrame_SetupController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow)
  536. {
  537. #if TARGET_OS_WIN32
  538. #pragma unused(theMoveWindow)
  539. #endif
  540.  
  541.     MovieController            myMC = NULL;
  542.     Rect                    myRect;
  543.     WindowObject            myWindowObject = NULL;
  544.     GrafPtr                    mySavedPort;
  545.  
  546.     if ((theMovie == NULL) || (theWindow == NULL))
  547.         return(NULL);
  548.         
  549.     // get our window specific data
  550.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  551.     if (myWindowObject == NULL)
  552.         return(NULL);
  553.         
  554.     GetPort(&mySavedPort);
  555.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  556.     
  557.     // resize the movie bounding rect and offset to 0,0
  558.     GetMovieBox(theMovie, &myRect);
  559.     MacOffsetRect(&myRect, -myRect.left, -myRect.top);
  560.     SetMovieBox(theMovie, &myRect);
  561.     AlignWindow(QTFrame_GetWindowFromWindowReference(theWindow), false, &myRect, NULL);
  562.  
  563.     // create the movie controller
  564.     myMC = NewMovieController(theMovie, &myRect, mcTopLeftMovie);
  565.     if (myMC == NULL)
  566.         return(NULL);
  567.         
  568.     // enable the default movie controller editing
  569.     MCEnableEditing(myMC, true);
  570.         
  571.     // suppress movie badge
  572.     MCDoAction(myMC, mcActionSetUseBadge, (void *)false);
  573.  
  574.     // set the initial looping state of the movie
  575.     QTUtils_SetLoopingStateFromFile(theMovie, myMC);
  576.     
  577.     // install an action filter that does any application-specific movie controller action processing
  578.     MCSetActionFilterWithRefCon(myMC, NewMCActionFilterWithRefConProc(QTApp_MCActionFilterProc), (long)myWindowObject);
  579.  
  580.     // add grow box for the movie controller
  581.     if ((**myWindowObject).fCanResizeWindow) {
  582. #if TARGET_OS_WIN32
  583.         RECT                myRect;
  584.  
  585.         GetWindowRect(GetDesktopWindow(), &myRect);
  586.         OffsetRect(&myRect, -myRect.left, -myRect.top);
  587.         QTFrame_ConvertWinToMacRect(&myRect, &gMCResizeBounds);
  588. #endif
  589. #if TARGET_OS_MAC
  590.         GetRegionBounds(GetGrayRgn(), &gMCResizeBounds);
  591. #endif
  592.  
  593.         MCDoAction(myMC, mcActionSetGrowBoxBounds, &gMCResizeBounds);
  594.     }
  595.     
  596. #if TARGET_OS_MAC
  597.     if (theMoveWindow)
  598.         MoveWindow(theWindow, kDefaultWindowX, kDefaultWindowY, false);
  599. #endif
  600.  
  601.     MacSetPort(mySavedPort);
  602.  
  603.     // add any application-specific controller functionality
  604.     QTApp_SetupController(myMC);
  605.         
  606.     return(myMC);
  607. }
  608.  
  609.  
  610. //////////
  611. //
  612. // QTFrame_SaveAsMovieFile
  613. // Save the movie in the specified window under a new name.
  614. //
  615. // Human interface guidelines for "Save As..." dictate that, if the user selects a new file name
  616. // for the current movie, then that new file shall become the active one. This means that we need
  617. // to close the current movie file and open the new one.
  618. //
  619. //////////
  620.  
  621. OSErr QTFrame_SaveAsMovieFile (WindowReference theWindow)
  622. {
  623.     WindowObject        myWindowObject = NULL;
  624.     Movie                 myMovie = NULL;
  625.     FSSpec                myFile;
  626.     Boolean                myIsSelected = false;
  627.     Boolean                myIsReplacing = false;    
  628.     StringPtr             myPrompt = QTUtils_ConvertCToPascalString(kSavePrompt);
  629.     StringPtr             myFileName = QTUtils_ConvertCToPascalString(kSaveMovieFileName);
  630.     OSErr                myErr = paramErr;
  631.     
  632.     // get the window object associated with the specified window
  633.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  634.     if (myWindowObject == NULL)
  635.         goto bail;
  636.         
  637.     myMovie = (**myWindowObject).fMovie;
  638.     if (myMovie == NULL)
  639.         goto bail;
  640.         
  641.     QTFrame_PutFile(myPrompt, myFileName, &myFile, &myIsSelected, &myIsReplacing);
  642.     if (myIsSelected) {
  643.         Movie            myNewMovie = NULL;
  644.         MovieController    myMC = NULL;
  645.         short            myRefNum = kInvalidFileRefNum;
  646.         short            myResID = movieInDataForkResID;
  647.         
  648.         //////////
  649.         //
  650.         // we have a valid FSSpec for the new movie file; now we want to flatten the existing
  651.         // movie into the new movie file, then open the new movie file and read the movie out
  652.         // of it; then we need to swap the window object data
  653.         //
  654.         //////////
  655.         
  656.         // delete any existing file of that name
  657.         if (myIsReplacing) {
  658.             myErr = DeleteMovieFile(&myFile);
  659.             if (myErr != noErr)
  660.                 goto bail;
  661.         }
  662.         
  663.         myNewMovie = FlattenMovieData(    myMovie,
  664.                                         flattenAddMovieToDataFork | flattenForceMovieResourceBeforeMovieData,
  665.                                         &myFile,
  666.                                         sigMoviePlayer,
  667.                                         smSystemScript,
  668.                                         createMovieFileDeleteCurFile | createMovieFileDontCreateResFile);
  669.         myErr = GetMoviesError();
  670.         if ((myNewMovie == NULL) || (myErr != noErr))
  671.             goto bail;
  672.  
  673.         // FlattenMovieData creates a new movie file and returns the movie to us; but it doesn't
  674.         // return the file reference number or the movie resource ID, which we want to have; so
  675.         // we will dump the movie returned by FlattenMovieData and open the movie file ourselves
  676.         DisposeMovie(myNewMovie);
  677.  
  678.         myErr = OpenMovieFile(&myFile, &myRefNum, fsRdWrPerm);
  679.         if (myErr != noErr)
  680.             goto bail;
  681.  
  682.         // get the new movie from the file
  683.         myErr = NewMovieFromFile(&myNewMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);        
  684.         if (myErr != noErr)
  685.             goto bail;
  686.  
  687.         // create a new movie controller
  688.         myMC = QTFrame_SetupController(myNewMovie, theWindow, false);
  689.         
  690.         //////////
  691.         //
  692.         // if we got to here, we've successfully created a new movie file, and NewMovieFromFile has
  693.         // returned the new movie to us; so we need to close down the current movie and install the
  694.         // new movie in its place
  695.         //
  696.         //////////
  697.         
  698.         // close the existing movie file
  699.         if ((**myWindowObject).fFileRefNum != kInvalidFileRefNum)
  700.             CloseMovieFile((**myWindowObject).fFileRefNum);
  701.         
  702.         // dispose of the existing movie controller and movie resource
  703.         if ((**myWindowObject).fController != NULL)
  704.             DisposeMovieController((**myWindowObject).fController);
  705.             
  706.         DisposeMovie(myMovie);
  707.         
  708.         // keep track of the new info
  709.         (**myWindowObject).fMovie = myNewMovie;
  710.         (**myWindowObject).fController = myMC;
  711.         (**myWindowObject).fFileFSSpec = myFile;
  712.         (**myWindowObject).fFileResID = myResID;
  713.         (**myWindowObject).fFileRefNum = myRefNum;
  714.         (**myWindowObject).fIsDirty = false;
  715.  
  716.         // make sure the movie uses the window GWorld in all situations
  717.         SetMovieGWorld(myNewMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference((**myWindowObject).fWindow), NULL);
  718.  
  719.         // set the window title
  720.         QTFrame_SetWindowTitleFromFSSpec(theWindow, &myFile, true);
  721.     } else {
  722.         myErr = userCanceledErr;
  723.     }
  724.  
  725. bail:
  726.     free(myPrompt);
  727.     free(myFileName);
  728.     
  729.     return(myErr);
  730. }
  731.  
  732.  
  733. //////////
  734. //
  735. // QTFrame_UpdateMovieFile
  736. // Update the file (if any) attached to the movie.
  737. //
  738. //////////
  739.  
  740. Boolean QTFrame_UpdateMovieFile (WindowReference theWindow)
  741. {
  742.     WindowObject        myWindowObject = NULL;
  743.     Movie                 myMovie = NULL;
  744.     OSErr                myErr = noErr;
  745.     
  746.     // get the window object associated with the specified window
  747.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  748.     if (myWindowObject == NULL)
  749.         return(false);
  750.         
  751.     myMovie = (**myWindowObject).fMovie;
  752.     if (myMovie == NULL)
  753.         return(false);
  754.     
  755.     // update the current volume setting
  756.     QTUtils_UpdateMovieVolumeSetting(myMovie);
  757.     
  758.     if ((**myWindowObject).fFileRefNum == kInvalidFileRefNum)        // brand new movie, so no file attached to it
  759.         myErr = QTFrame_SaveAsMovieFile(theWindow);
  760.     else                                                            // we have an existing file; just update the movie resource
  761.         myErr = UpdateMovieResource(myMovie, (**myWindowObject).fFileRefNum, (**myWindowObject).fFileResID, NULL);
  762.     
  763.     (**myWindowObject).fIsDirty = false;
  764.  
  765.     return(myErr == noErr);
  766. }
  767.  
  768.  
  769. //////////
  770. //
  771. // QTFrame_IdleMovieWindows
  772. // Do idle-time processing on all open movie windows.
  773. //
  774. //////////
  775.  
  776. void QTFrame_IdleMovieWindows (void)
  777. {    
  778.     WindowReference            myWindow = NULL;
  779.     MovieController            myMC = NULL;
  780.     
  781.     myWindow = QTFrame_GetFrontMovieWindow();
  782.     while (myWindow != NULL) {
  783.         myMC = QTFrame_GetMCFromWindow(myWindow);
  784.         if (myMC != NULL)
  785.             MCIdle(myMC);
  786.             
  787.         QTApp_Idle(myWindow);
  788.         
  789.         myWindow = QTFrame_GetNextMovieWindow(myWindow);
  790.     }
  791. }
  792.  
  793.  
  794. //////////
  795. //
  796. // QTFrame_CloseMovieWindows
  797. // Close all open movie windows.
  798. //
  799. //////////
  800.  
  801. void QTFrame_CloseMovieWindows (void)
  802. {
  803. #if TARGET_OS_MAC    
  804.     WindowReference            myWindow = NULL;
  805.     WindowReference            myNextWindow = NULL;
  806.  
  807.     myWindow = QTFrame_GetFrontMovieWindow();
  808.     while (myWindow != NULL) {
  809.         myNextWindow = QTFrame_GetNextMovieWindow(myWindow);
  810.         QTFrame_DestroyMovieWindow(myWindow);
  811.         myWindow = myNextWindow;
  812.     }
  813. #endif
  814. #if TARGET_OS_WIN32
  815.     SendMessage(ghWnd, WM_COMMAND, (WPARAM)IDM_WINDOWCLOSEALL, 0L);
  816. #endif
  817. }
  818.  
  819.  
  820. //////////
  821. //
  822. // QTFrame_CreateWindowObject
  823. // Create a new window object associated with the specified window.
  824. //
  825. //////////
  826.  
  827. void QTFrame_CreateWindowObject (WindowReference theWindow)
  828. {
  829.     WindowObject            myWindowObject = NULL;
  830.  
  831.     if (theWindow == NULL)
  832.         return;
  833.         
  834.     // allocate space for a window object record and fill in some of its fields
  835.     myWindowObject = (WindowObject)NewHandleClear(sizeof(WindowObjectRecord));
  836.     if (myWindowObject != NULL) {
  837.         (**myWindowObject).fWindow = theWindow;
  838.         (**myWindowObject).fController = NULL;
  839.         (**myWindowObject).fObjectType = kApplicationSignature;
  840.         (**myWindowObject).fCanResizeWindow = true;
  841.         (**myWindowObject).fInstance = NULL;
  842.         (**myWindowObject).fIsDirty = false;
  843.         (**myWindowObject).fAppData = NULL;
  844.     }
  845.     
  846.     // associate myWindowObject (which may be NULL) with the window
  847. #if TARGET_OS_MAC
  848.     SetWRefCon(theWindow, (long)myWindowObject);
  849. #endif
  850. #if TARGET_OS_WIN32
  851.     SetWindowLong(theWindow, GWL_USERDATA, (LPARAM)myWindowObject);
  852.     
  853.     // associate a GrafPort with this window 
  854.     CreatePortAssociation(theWindow, NULL, 0L);
  855. #endif
  856.     
  857.     // set the current port to the new window
  858.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  859. }
  860.  
  861.  
  862. //////////
  863. //
  864. // QTFrame_CloseWindowObject
  865. // Close a window object and any associated data.
  866. //
  867. //////////
  868.  
  869. void QTFrame_CloseWindowObject (WindowObject theWindowObject)
  870. {
  871.     if (theWindowObject == NULL)
  872.         return;
  873.         
  874.     // close the movie file
  875.     if ((**theWindowObject).fFileRefNum != kInvalidFileRefNum) {
  876.         CloseMovieFile((**theWindowObject).fFileRefNum);
  877.         (**theWindowObject).fFileRefNum = kInvalidFileRefNum;
  878.     }
  879.     
  880.     // dispose movie controller and movie 
  881.     if ((**theWindowObject).fController != NULL) {
  882.         MCSetActionFilterWithRefCon((**theWindowObject).fController, NULL, 0L);
  883.         DisposeMovieController((**theWindowObject).fController);
  884.         (**theWindowObject).fController = NULL;
  885.     }
  886.     
  887.     if ((**theWindowObject).fMovie != NULL) {
  888.         DisposeMovie((**theWindowObject).fMovie);
  889.         (**theWindowObject).fMovie = NULL;
  890.     }
  891.     
  892.     // close the graphics importer, if any
  893.     if ((**theWindowObject).fGraphicsImporter != NULL) {
  894.         CloseComponent((**theWindowObject).fGraphicsImporter);
  895.         (**theWindowObject).fGraphicsImporter = NULL;
  896.     }
  897.     
  898.     // do any application-specific window clean-up
  899.     QTApp_RemoveWindowObject(theWindowObject);
  900.     
  901.     DisposeHandle((Handle)theWindowObject);
  902. }
  903.  
  904.  
  905. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  906. //
  907. // Window-walking utilities.
  908. //
  909. // Use these functions to iterate through all windows or movie windows belonging to the application.
  910. //
  911. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  912.  
  913. //////////
  914. //
  915. // QTFrame_GetFrontAppWindow
  916. // Return a reference to the frontmost application window (whether or not it's a movie window).
  917. //
  918. //////////
  919.  
  920. WindowReference QTFrame_GetFrontAppWindow (void)
  921. {
  922. #if TARGET_OS_MAC
  923.     return(FrontWindow());
  924. #endif
  925. #if TARGET_OS_WIN32
  926.     return(GetWindow(ghWnd, GW_HWNDFIRST));
  927. #endif
  928. }
  929.  
  930.  
  931. //////////
  932. //
  933. // QTFrame_GetNextAppWindow
  934. // Return a reference to the next application window (whether or not it's a movie window).
  935. //
  936. //////////
  937.  
  938. WindowReference QTFrame_GetNextAppWindow (WindowReference theWindow)
  939. {
  940. #if TARGET_OS_MAC
  941.     return(theWindow == NULL ? NULL : GetNextWindow(theWindow));
  942. #endif
  943. #if TARGET_OS_WIN32
  944.     return(GetWindow(theWindow, GW_HWNDNEXT));
  945. #endif
  946. }
  947.  
  948.  
  949. //////////
  950. //
  951. // QTFrame_GetFrontMovieWindow
  952. // Return a reference to the frontmost movie window.
  953. //
  954. //////////
  955.  
  956. WindowReference QTFrame_GetFrontMovieWindow (void)
  957. {
  958.     WindowReference            myWindow;
  959.  
  960. #if TARGET_OS_MAC
  961.     myWindow = QTFrame_GetFrontAppWindow();
  962.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  963.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  964. #endif
  965.  
  966. #if TARGET_OS_WIN32
  967.     myWindow = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  968. #endif
  969.  
  970.     return(myWindow);
  971. }
  972.  
  973.  
  974. //////////
  975. //
  976. // QTFrame_GetNextMovieWindow
  977. // Return a reference to the next movie window.
  978. //
  979. //////////
  980.  
  981. WindowReference QTFrame_GetNextMovieWindow (WindowReference theWindow)
  982. {
  983.     WindowReference            myWindow;
  984.  
  985. #if TARGET_OS_MAC
  986.     myWindow = QTFrame_GetNextAppWindow(theWindow);
  987.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  988.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  989. #endif
  990.  
  991. #if TARGET_OS_WIN32
  992.     myWindow = GetWindow(theWindow, GW_HWNDNEXT);
  993. #endif
  994.  
  995.     return(myWindow);
  996. }
  997.  
  998.  
  999. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1000. //
  1001. // Data-retrieval utilities.
  1002. //
  1003. // Use the following functions to retrieve the window object, the application-specific data, or the movie
  1004. // controller that is associated with a window.
  1005. //
  1006. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1007.  
  1008. //////////
  1009. //
  1010. // QTFrame_GetWindowObjectFromFrontWindow
  1011. // Get the window object (if any) associated with the front window.
  1012. //
  1013. //////////
  1014.  
  1015. WindowObject QTFrame_GetWindowObjectFromFrontWindow (void)
  1016. {
  1017.     return(QTFrame_GetWindowObjectFromWindow(QTFrame_GetFrontMovieWindow()));
  1018. }
  1019.  
  1020.  
  1021. //////////
  1022. //
  1023. // QTFrame_GetWindowObjectFromWindow
  1024. // Get the window object (if any) associated with the specified window.
  1025. //
  1026. //////////
  1027.  
  1028. WindowObject QTFrame_GetWindowObjectFromWindow (WindowReference theWindow)
  1029. {
  1030.     WindowObject        myWindowObject = NULL;
  1031.  
  1032.     if (!QTFrame_IsAppWindow(theWindow))
  1033.         return(NULL);
  1034.             
  1035. #if TARGET_OS_MAC
  1036.     myWindowObject = (WindowObject)GetWRefCon(theWindow);
  1037. #endif
  1038. #if TARGET_OS_WIN32
  1039.     myWindowObject = (WindowObject)GetWindowLong(theWindow, GWL_USERDATA);
  1040. #endif
  1041.  
  1042.     // make sure this is a window object
  1043.     if (!QTFrame_IsWindowObjectOurs(myWindowObject))
  1044.         return(NULL);
  1045.         
  1046.     return(myWindowObject);
  1047. }
  1048.  
  1049.  
  1050. //////////
  1051. //
  1052. // QTFrame_GetMCFromFrontWindow
  1053. // Get the movie controller (if any) associated with the front window.
  1054. //
  1055. //////////
  1056.  
  1057. MovieController QTFrame_GetMCFromFrontWindow (void)
  1058. {
  1059.     return(QTFrame_GetMCFromWindow(QTFrame_GetFrontMovieWindow()));
  1060. }
  1061.  
  1062.  
  1063. //////////
  1064. //
  1065. // QTFrame_GetMCFromWindow
  1066. // Get the movie controller (if any) associated with the specified window.
  1067. //
  1068. //////////
  1069.  
  1070. MovieController QTFrame_GetMCFromWindow (WindowReference theWindow)
  1071. {
  1072.     MovieController     myMC = NULL;
  1073.     WindowObject        myWindowObject = NULL;
  1074.         
  1075.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1076.     if (myWindowObject != NULL)
  1077.         myMC = (**myWindowObject).fController;
  1078.         
  1079.     return(myMC);
  1080. }
  1081.  
  1082.  
  1083. //////////
  1084. //
  1085. // QTFrame_GetQTVRInstanceFromFrontWindow
  1086. // Get the QTVRInstance (if any) associated with the front window.
  1087. //
  1088. //////////
  1089.  
  1090. QTVRInstance QTFrame_GetQTVRInstanceFromFrontWindow (void)
  1091. {
  1092.     return(QTFrame_GetQTVRInstanceFromWindow(QTFrame_GetFrontMovieWindow()));
  1093. }
  1094.  
  1095.  
  1096. //////////
  1097. //
  1098. // QTFrame_GetQTVRInstanceFromWindow
  1099. // Get the QTVRInstance (if any) associated with the specified window.
  1100. //
  1101. //////////
  1102.  
  1103. QTVRInstance QTFrame_GetQTVRInstanceFromWindow (WindowReference theWindow)
  1104. {
  1105.     QTVRInstance         myInstance = NULL;
  1106.     WindowObject        myWindowObject = NULL;
  1107.     
  1108.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1109.     if (myWindowObject != NULL)
  1110.         myInstance = (**myWindowObject).fInstance;
  1111.         
  1112.     return(myInstance);
  1113. }
  1114.  
  1115.  
  1116. //////////
  1117. //
  1118. // QTFrame_GetAppDataFromFrontWindow
  1119. // Get the application-specific data associated with the front window.
  1120. //
  1121. //////////
  1122.  
  1123. Handle QTFrame_GetAppDataFromFrontWindow (void)
  1124. {
  1125.     return(QTFrame_GetAppDataFromWindow(QTFrame_GetFrontMovieWindow()));
  1126. }
  1127.  
  1128.  
  1129. //////////
  1130. //
  1131. // QTFrame_GetAppDataFromWindow
  1132. // Get the application-specific data associated with the specified window.
  1133. //
  1134. //////////
  1135.  
  1136. Handle QTFrame_GetAppDataFromWindow (WindowReference theWindow)
  1137. {
  1138.     WindowObject        myWindowObject = NULL;
  1139.     
  1140.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1141.     if (myWindowObject == NULL)
  1142.         return(NULL);
  1143.         
  1144.     return(QTFrame_GetAppDataFromWindowObject(myWindowObject));
  1145. }
  1146.  
  1147.  
  1148. //////////
  1149. //
  1150. // QTFrame_GetAppDataFromWindowObject
  1151. // Get the application-specific data associated with the specified window object.
  1152. //
  1153. //////////
  1154.  
  1155. Handle QTFrame_GetAppDataFromWindowObject (WindowObject theWindowObject)
  1156. {
  1157.     // make sure this is a window object belonging to our application
  1158.     if (!QTFrame_IsWindowObjectOurs(theWindowObject))
  1159.         return(NULL);
  1160.     
  1161.     return((**theWindowObject).fAppData);
  1162. }
  1163.  
  1164.  
  1165. //////////
  1166. //
  1167. // QTFrame_IsWindowObjectOurs
  1168. // Does the specified window object belong to our application?
  1169. //
  1170. //////////
  1171.  
  1172. Boolean QTFrame_IsWindowObjectOurs (WindowObject theWindowObject)
  1173. {
  1174.     OSType        myType = 0L;
  1175.  
  1176.     if ((theWindowObject == NULL) || (*theWindowObject == NULL))
  1177.         return(false);
  1178.         
  1179.     myType = (**theWindowObject).fObjectType;
  1180.     return(myType == kApplicationSignature);
  1181. }
  1182.  
  1183.  
  1184. //////////
  1185. //
  1186. // QTFrame_IsAppWindow
  1187. // Does the specified window belong to our application?
  1188. //
  1189. //////////
  1190.  
  1191. Boolean QTFrame_IsAppWindow (WindowReference theWindow)
  1192. {
  1193.     if (theWindow == NULL)
  1194.         return(false);
  1195.  
  1196. #if TARGET_OS_MAC
  1197.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  1198. #endif
  1199. #if TARGET_OS_WIN32
  1200.     return(true);
  1201. #endif
  1202. }
  1203.  
  1204.  
  1205. //////////
  1206. //
  1207. // QTFrame_IsDocWindow
  1208. // Is the specified window a document window (having a WindowObject refcon)?
  1209. //
  1210. //////////
  1211.  
  1212. Boolean QTFrame_IsDocWindow (WindowReference theWindow)
  1213. {
  1214.     if (theWindow == NULL)
  1215.         return(false);
  1216.  
  1217. #if TARGET_OS_MAC
  1218.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  1219. #endif
  1220. #if TARGET_OS_WIN32
  1221.     return(true);
  1222. #endif
  1223. }
  1224.  
  1225.  
  1226. //////////
  1227. //
  1228. // QTFrame_ActivateController
  1229. // Activate or deactivate the movie controller in the specified window.
  1230. //
  1231. //////////
  1232.  
  1233. void QTFrame_ActivateController (WindowReference theWindow, Boolean IsActive)
  1234. {
  1235.     WindowObject         myWindowObject = NULL;
  1236.     MovieController        myMC = NULL;
  1237.     GrafPtr                mySavedPort = NULL;
  1238.     
  1239.     if (theWindow == NULL)
  1240.         return;
  1241.     
  1242.     GetPort(&mySavedPort);
  1243.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  1244.     
  1245.     // get the window object associated with the specified window
  1246.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1247.     if (myWindowObject != NULL) {
  1248.         myMC = (**myWindowObject).fController;
  1249.         if (myMC != NULL)
  1250.             MCActivate(myMC, QTFrame_GetWindowFromWindowReference(theWindow), IsActive);
  1251.     }
  1252.     
  1253.     MacSetPort(mySavedPort);
  1254. }
  1255.  
  1256.  
  1257. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1258. //
  1259. // Miscellaneous utilities.
  1260. //
  1261. // Use the following functions to play beeps, manipulate menus, and do other miscellaneous things.
  1262. //
  1263. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1264.  
  1265. //////////
  1266. //
  1267. // QTFrame_Beep
  1268. // Beep.
  1269. //
  1270. //////////
  1271.  
  1272. void QTFrame_Beep (void)
  1273. {
  1274. #if TARGET_OS_MAC
  1275.     SysBeep(30);
  1276. #endif
  1277. #if TARGET_OS_WIN32
  1278.     MessageBeep(MB_OK);
  1279. #endif
  1280. }
  1281.  
  1282.  
  1283. //////////
  1284. //
  1285. // QTFrame_SetMenuState
  1286. // Set the enabled/disabled state of a menu.
  1287. //
  1288. // On Windows, the theMenuItem parameter must be the (0-based) index in the menu bar of the
  1289. // desired pull-down menu.
  1290. //
  1291. //////////
  1292.  
  1293. void QTFrame_SetMenuState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  1294. {
  1295. #if TARGET_OS_MAC
  1296. #pragma unused(theMenuItem)
  1297.     QTFrame_SetMenuItemState(theMenu, 0, theState);        // menu item == 0 means the entire menu
  1298. #endif
  1299. #if TARGET_OS_WIN32
  1300.     QTFrame_SetMenuItemState(theMenu, theMenuItem, theState | MF_BYPOSITION);
  1301. #endif
  1302. }
  1303.  
  1304.  
  1305. //////////
  1306. //
  1307. // QTFrame_SetMenuItemState
  1308. // Set the enabled/disabled state of a menu item.
  1309. //
  1310. // When running under MacOS 8.5.1, EnableMenuItem and DisableMenuItem seem to do nasty things
  1311. // to the keyboard equivalents associated with a menu; so we'll work around that problem here.
  1312. //
  1313. //////////
  1314.  
  1315. void QTFrame_SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  1316. {
  1317. #if TARGET_OS_MAC
  1318.     UInt8        myModifiers;
  1319.     
  1320.     // get the existing menu item modifiers
  1321.     GetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), &myModifiers);
  1322.     
  1323.     if (theState == kEnableMenuItem)
  1324.         EnableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  1325.     else
  1326.         DisableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  1327.         
  1328.     // restore the previous menu item modifiers
  1329.     SetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), myModifiers);
  1330. #endif
  1331. #if TARGET_OS_WIN32
  1332.     EnableMenuItem(theMenu, (UINT)theMenuItem, (UINT)theState);
  1333. #endif
  1334. }
  1335.  
  1336.  
  1337. //////////
  1338. //
  1339. // QTFrame_SetMenuItemLabel
  1340. // Set the label (that is, the text) of a menu item.
  1341. //
  1342. //////////
  1343.  
  1344. void QTFrame_SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText)
  1345. {
  1346. #if TARGET_OS_MAC
  1347.     Str255        myString;
  1348.     short        mySIndex, myTIndex;
  1349.  
  1350.     // we need to remove the '&' character while converting to a Pascal string    
  1351.     mySIndex = 1;
  1352.     for (myTIndex = 0; myTIndex < strlen(theText); myTIndex++) {
  1353.         if (theText[myTIndex] != '&') {
  1354.             myString[mySIndex] = theText[myTIndex];
  1355.             mySIndex++;
  1356.         }
  1357.     }
  1358.     
  1359.     myString[0] = mySIndex - 1;
  1360.     
  1361.     SetMenuItemText(theMenu, MENU_ITEM(theMenuItem), myString);
  1362. #endif
  1363. #if TARGET_OS_WIN32
  1364.     UINT        myState;
  1365.     
  1366.     // make sure that we preserve the current menu state
  1367.     myState = GetMenuState(theMenu, (UINT)theMenuItem, MF_BYCOMMAND);
  1368.     ModifyMenu(theMenu, (UINT)theMenuItem, MF_BYCOMMAND | MF_STRING | myState, (UINT)theMenuItem, (LPSTR)theText);
  1369. #endif
  1370. }
  1371.  
  1372.  
  1373. //////////
  1374. //
  1375. // QTFrame_SetMenuItemCheck
  1376. // Set the check mark state state of a menu item.
  1377. //
  1378. //////////
  1379.  
  1380. void QTFrame_SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState)
  1381. {
  1382. #if TARGET_OS_MAC
  1383.     MacCheckMenuItem(theMenu, MENU_ITEM(theMenuItem), theState);
  1384. #endif
  1385. #if TARGET_OS_WIN32
  1386.     CheckMenuItem(theMenu, (UINT)theMenuItem, theState ? MF_CHECKED : MF_UNCHECKED);
  1387. #endif
  1388. }
  1389.  
  1390.  
  1391. //////////
  1392. //
  1393. // QTFrame_GetPortFromWindowReference 
  1394. // Return the graphics port associated with a window reference.
  1395. //
  1396. //////////
  1397.  
  1398. GrafPtr QTFrame_GetPortFromWindowReference (WindowReference theWindow)
  1399. {
  1400. #if TARGET_OS_MAC
  1401.     return((GrafPtr)GetWindowPort(theWindow));
  1402. #endif
  1403. #if TARGET_OS_WIN32
  1404.     return(GetNativeWindowPort(theWindow));
  1405. #endif
  1406. }
  1407.  
  1408.  
  1409. //////////
  1410. //
  1411. // QTFrame_GetWindowReferenceFromPort
  1412. // Return the window reference associated with a graphics port.
  1413. //
  1414. //////////
  1415.  
  1416. WindowReference QTFrame_GetWindowReferenceFromPort (GrafPtr thePort)
  1417. {
  1418. #if TARGET_OS_MAC
  1419.     return((WindowReference)GetWindowFromPort((CGrafPtr)thePort));
  1420. #endif
  1421. #if TARGET_OS_WIN32
  1422.     return((WindowReference)GetPortNativeWindow(thePort));
  1423. #endif
  1424. }
  1425.  
  1426.  
  1427. //////////
  1428. //
  1429. // QTFrame_GetWindowFromWindowReference
  1430. // Return the Macintosh window associated with a window reference.
  1431. //
  1432. //////////
  1433.  
  1434. WindowPtr QTFrame_GetWindowFromWindowReference (WindowReference theWindow)
  1435. {
  1436. #if TARGET_OS_MAC
  1437.     return((WindowPtr)theWindow);
  1438. #endif
  1439. #if TARGET_OS_WIN32
  1440.     return((WindowPtr)GetNativeWindowPort(theWindow));
  1441. #endif
  1442. }
  1443.  
  1444.  
  1445. /////////
  1446. //
  1447. // QTFrame_GetWindowWidth
  1448. // Return the width of the specified window.
  1449. //
  1450. //////////
  1451.  
  1452. short QTFrame_GetWindowWidth (WindowReference theWindow)
  1453. {
  1454. #if TARGET_OS_MAC
  1455.     Rect        myRect = {0, 0, 0, 0};
  1456.  
  1457.     if (theWindow != NULL)
  1458.         GetWindowPortBounds(theWindow, &myRect);
  1459. #endif
  1460. #if TARGET_OS_WIN32
  1461.     RECT        myRect = {0L, 0L, 0L, 0L};
  1462.  
  1463.     if (theWindow != NULL)
  1464.         GetWindowRect(theWindow, &myRect);
  1465. #endif
  1466.  
  1467.     return((short)(myRect.right - myRect.left));
  1468. }
  1469.  
  1470.  
  1471. //////////
  1472. //
  1473. // QTFrame_SetWindowTitleFromFSSpec
  1474. // Set the title of the specified window, using the name contained in the specified FSSpec.
  1475. //
  1476. //////////
  1477.  
  1478. void QTFrame_SetWindowTitleFromFSSpec (WindowReference theWindow, FSSpecPtr theFSSpecPtr, Boolean theAddToRecentDocs)
  1479. {
  1480. #if TARGET_OS_MAC
  1481. #pragma unused(theAddToRecentDocs)
  1482.     SetWTitle(theWindow, theFSSpecPtr->name);
  1483. #endif
  1484. #if TARGET_OS_WIN32
  1485.     char    *myTempName;
  1486.     char    myWindName[MAX_PATH];
  1487.  
  1488.     // get the full pathname contained in the FSSpec (which is a Str255)
  1489.     myTempName = QTUtils_ConvertPascalToCString(theFSSpecPtr->name);
  1490.  
  1491.     // get the movie file name from the full pathname
  1492.     QTFrame_GetDisplayName(myTempName, myWindName);
  1493.  
  1494.     // set the window title
  1495.     SetWindowText(theWindow, myWindName);
  1496.     
  1497.     // add this document to the Documents list, if so instructed
  1498.     if (theAddToRecentDocs)
  1499.         SHAddToRecentDocs(SHARD_PATH, myTempName);
  1500.     
  1501.     free(myTempName);
  1502. #endif
  1503. }
  1504.  
  1505.  
  1506. //////////
  1507. //
  1508. // QTFrame_SizeWindowToMovie
  1509. // Set the window size to exactly fit the movie and controller (if visible).
  1510. //
  1511. //////////
  1512.  
  1513. void QTFrame_SizeWindowToMovie (WindowObject theWindowObject)
  1514. {
  1515.     Rect                    myMovieBounds;
  1516.     Movie                    myMovie = NULL;
  1517.     MovieController            myMC = NULL;
  1518.     GraphicsImportComponent    myImporter = NULL;
  1519.  
  1520. #if TARGET_OS_WIN32
  1521.     gWeAreSizingWindow = true;
  1522. #endif
  1523.  
  1524.     if (theWindowObject == NULL)
  1525.         goto bail;
  1526.     
  1527.     myMovie = (**theWindowObject).fMovie;
  1528.     myMC = (**theWindowObject).fController;
  1529.     myImporter = (**theWindowObject).fGraphicsImporter;
  1530.  
  1531.     if (myImporter != NULL) {
  1532.         GraphicsImportGetBoundsRect(myImporter, &myMovieBounds);
  1533.         goto gotBounds;
  1534.     }
  1535.  
  1536.     if (myMovie == NULL)
  1537.         return;
  1538.  
  1539.     GetMovieBox(myMovie, &myMovieBounds);
  1540.  
  1541.     if (myMC != NULL)
  1542.         if (MCGetVisible(myMC))
  1543.             MCGetControllerBoundsRect(myMC, &myMovieBounds);
  1544.     
  1545.     // make sure that the movie has a non-zero width;
  1546.     // a zero height is okay (for example, with a music movie with no controller bar)
  1547.     if (myMovieBounds.right - myMovieBounds.left == 0) {
  1548.         myMovieBounds.left = 0;
  1549.         myMovieBounds.right = QTFrame_GetWindowWidth((**theWindowObject).fWindow);
  1550.     }
  1551.  
  1552. gotBounds:    
  1553.     SizeWindow(QTFrame_GetWindowFromWindowReference((**theWindowObject).fWindow),
  1554.                                             myMovieBounds.right - myMovieBounds.left,
  1555.                                             myMovieBounds.bottom - myMovieBounds.top,
  1556.                                             true);
  1557.  
  1558. bail:                                        
  1559. #if TARGET_OS_WIN32
  1560.     gWeAreSizingWindow = false;
  1561. #endif
  1562.  
  1563.     return;
  1564. }
  1565.  
  1566.  
  1567. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1568. //
  1569. // File-opening and -saving utilities.
  1570. //
  1571. // The functions are meant to provide replacements for StandardGetFilePreview and StandardPutFile, which
  1572. // are not supported under Carbon. However, Navigation Services is not (yet, at any rate) supported under
  1573. // Windows, so we still need to call through to the Standard File Package.
  1574. //
  1575. // The Navigation Services portion of this code is based selectively on the file NavigationServicesSupport.c
  1576. // by Yan Arrouye and on the developer documentation "Programming With Navigation Services 1.1". The code that
  1577. // determines which files can be opened by QuickTime is based on code by Sam Bushell in CarbonMovieEditor.c.
  1578. //
  1579. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1580.  
  1581. //////////
  1582. //
  1583. // QTFrame_PutFile
  1584. // Save a file under the specified name. Return Boolean values indicating whether the user selected a file
  1585. // and whether the selected file is replacing an existing file.
  1586. //
  1587. //////////
  1588.  
  1589. OSErr QTFrame_PutFile (ConstStr255Param thePrompt, ConstStr255Param theFileName, FSSpecPtr theFSSpecPtr, Boolean *theIsSelected, Boolean *theIsReplacing)
  1590. {
  1591. #if TARGET_OS_WIN32
  1592.     StandardFileReply    myReply;
  1593. #endif
  1594. #if TARGET_OS_MAC
  1595.     NavReplyRecord        myReply;
  1596.     NavDialogOptions    myDialogOptions;
  1597.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1598. #endif
  1599.     OSErr                myErr = noErr;
  1600.  
  1601.     if ((theFSSpecPtr == NULL) || (theIsSelected == NULL) || (theIsReplacing == NULL))
  1602.         return(paramErr);
  1603.     
  1604.     // deactivate any frontmost movie window
  1605.     QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1606.  
  1607.     // assume we are not replacing an existing file
  1608.     *theIsReplacing = false;
  1609.     
  1610. #if TARGET_OS_WIN32
  1611.     StandardPutFile(thePrompt, theFileName, &myReply);
  1612.     *theFSSpecPtr = myReply.sfFile;
  1613.     *theIsSelected = myReply.sfGood;
  1614.     if (myReply.sfGood)
  1615.         *theIsReplacing = myReply.sfReplacing;
  1616. #endif
  1617.  
  1618. #if TARGET_OS_MAC
  1619.     // specify the options for the dialog box
  1620.     NavGetDefaultDialogOptions(&myDialogOptions);
  1621.     myDialogOptions.dialogOptionFlags += kNavNoTypePopup;
  1622.     myDialogOptions.dialogOptionFlags += kNavDontAutoTranslate;
  1623.     BlockMoveData(theFileName, myDialogOptions.savedFileName, theFileName[0] + 1);
  1624.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1625.     BlockMoveData(thePrompt, myDialogOptions.message, thePrompt[0] + 1);
  1626.     
  1627.     // prompt the user for a file
  1628.     myErr = NavPutFile(NULL, &myReply, &myDialogOptions, myEventUPP, MovieFileType, sigMoviePlayer, NULL);
  1629.     if ((myErr == noErr) && myReply.validRecord) {
  1630.         AEKeyword        myKeyword;
  1631.         DescType        myActualType;
  1632.         Size            myActualSize = 0;
  1633.         
  1634.         // get the FSSpec for the selected file
  1635.         if (theFSSpecPtr != NULL)
  1636.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1637.  
  1638.         NavDisposeReply(&myReply);
  1639.     }
  1640.         
  1641.     *theIsSelected = myReply.validRecord;
  1642.     if (myReply.validRecord)
  1643.         *theIsReplacing = myReply.replacing;
  1644.  
  1645.     DisposeNavEventUPP(myEventUPP);
  1646. #endif
  1647.  
  1648.     return(myErr);
  1649. }
  1650.     
  1651.  
  1652. //////////
  1653. //
  1654. // QTFrame_GetOneFileWithPreview
  1655. // Display the appropriate file-opening dialog box, with an optional QuickTime preview pane. If the user
  1656. // selects a file, return information about it using the theFSSpecPtr parameter.
  1657. //
  1658. // Note that both StandardGetFilePreview and NavGetFile use the function specified by theFilterProc as a
  1659. // file filter. This framework always passes NULL in the theFilterProc parameter. If you use this function
  1660. // in your own code, keep in mind that on Windows the function specifier must be of type FileFilterUPP and 
  1661. // on Macintosh it must be of type NavObjectFilterUPP. (You can use the QTFrame_GetFileFilterUPP to create
  1662. // a function specifier of the appropriate type.) Also keep in mind that Navigation Services expects a file 
  1663. // filter function to return true if a file is to be displayed, while the Standard File Package expects the
  1664. // filter to return false if a file is to be displayed.
  1665. //
  1666. //////////
  1667.  
  1668. OSErr QTFrame_GetOneFileWithPreview (short theNumTypes, QTFrameTypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc)
  1669. {
  1670. #if TARGET_OS_WIN32
  1671.     StandardFileReply    myReply;
  1672. #endif
  1673. #if TARGET_OS_MAC
  1674.     NavReplyRecord        myReply;
  1675.     NavDialogOptions    myDialogOptions;
  1676.     NavTypeListHandle    myOpenList = NULL;
  1677.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1678. #endif
  1679.     OSErr                myErr = noErr;
  1680.     
  1681.     if (theFSSpecPtr == NULL)
  1682.         return(paramErr);
  1683.     
  1684.     // deactivate any frontmost movie window
  1685.     QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1686.  
  1687. #if TARGET_OS_WIN32
  1688.     // prompt the user for a file
  1689.     StandardGetFilePreview((FileFilterUPP)theFilterProc, theNumTypes, (ConstSFTypeListPtr)theTypeList, &myReply);
  1690.     if (!myReply.sfGood)
  1691.         return(userCanceledErr);
  1692.     
  1693.     // make an FSSpec record
  1694.     myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, myReply.sfFile.parID, myReply.sfFile.name, theFSSpecPtr);
  1695. #endif
  1696.  
  1697. #if TARGET_OS_MAC
  1698.     // specify the options for the dialog box
  1699.     NavGetDefaultDialogOptions(&myDialogOptions);
  1700.     myDialogOptions.dialogOptionFlags -= kNavNoTypePopup;
  1701.     myDialogOptions.dialogOptionFlags -= kNavAllowMultipleFiles;
  1702.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1703.     
  1704.     // create a handle to an 'open' resource
  1705.     myOpenList = (NavTypeListHandle)QTFrame_CreateOpenHandle(kApplicationSignature, theNumTypes, theTypeList);
  1706.     if (myOpenList != NULL)
  1707.         HLock((Handle)myOpenList);
  1708.     
  1709.     // prompt the user for a file
  1710.     myErr = NavGetFile(NULL, &myReply, &myDialogOptions, myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, myOpenList, NULL);
  1711.     if ((myErr == noErr) && myReply.validRecord) {
  1712.         AEKeyword        myKeyword;
  1713.         DescType        myActualType;
  1714.         Size            myActualSize = 0;
  1715.         
  1716.         // get the FSSpec for the selected file
  1717.         if (theFSSpecPtr != NULL)
  1718.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1719.  
  1720.         NavDisposeReply(&myReply);
  1721.     }
  1722.     
  1723.     if (myOpenList != NULL) {
  1724.         HUnlock((Handle)myOpenList);
  1725.         DisposeHandle((Handle)myOpenList);
  1726.     }
  1727.     
  1728.     DisposeNavEventUPP(myEventUPP);
  1729. #endif
  1730.  
  1731.     return(myErr);
  1732. }
  1733.  
  1734.  
  1735. //////////
  1736. //
  1737. // QTFrame_HandleNavEvent
  1738. // A callback procedure that handles events while a Navigation Service dialog box is displayed.
  1739. //
  1740. //////////
  1741.  
  1742. PASCAL_RTN void QTFrame_HandleNavEvent (NavEventCallbackMessage theCallBackSelector, NavCBRecPtr theCallBackParms, void *theCallBackUD)
  1743. {
  1744. #pragma unused(theCallBackUD)
  1745.     
  1746.     if (theCallBackParms == NULL)
  1747.         return;
  1748.  
  1749.     if (theCallBackParms->eventData.eventDataParms.event == NULL)
  1750.         return;
  1751.  
  1752.     if (theCallBackSelector == kNavCBEvent) {
  1753.         switch (theCallBackParms->eventData.eventDataParms.event->what) {
  1754.             case updateEvt:
  1755.             case activateEvt:
  1756. #if TARGET_OS_MAC
  1757.                 QTFrame_HandleEvent(theCallBackParms->eventData.eventDataParms.event);
  1758. #endif
  1759.                 break;
  1760.             case nullEvent:
  1761.                 QTFrame_IdleMovieWindows();
  1762.                 break;
  1763.         }
  1764.     }
  1765. }
  1766.  
  1767.  
  1768. //////////
  1769. //
  1770. // QTFrame_CreateOpenHandle
  1771. // Return a handle to a dynamically-created 'open' resource.
  1772. //
  1773. //////////
  1774.  
  1775. Handle QTFrame_CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, QTFrameTypeListPtr theTypeList)
  1776. {
  1777.     Handle            myHandle = NULL;
  1778.     
  1779.     if (theTypeList == NULL)
  1780.         return(myHandle);
  1781.     
  1782.     if (theNumTypes > 0) {
  1783.         myHandle = NewHandle(sizeof(NavTypeList) + (theNumTypes * sizeof(OSType)));
  1784.         if (myHandle != NULL) {
  1785.             NavTypeListHandle     myOpenResHandle    = (NavTypeListHandle)myHandle;
  1786.             
  1787.             (*myOpenResHandle)->componentSignature = theApplicationSignature;
  1788.             (*myOpenResHandle)->osTypeCount = theNumTypes;
  1789.             BlockMoveData(theTypeList, (*myOpenResHandle)->osType, theNumTypes * sizeof(OSType));
  1790.         }
  1791.     }
  1792.     
  1793.     return(myHandle);
  1794. }
  1795.  
  1796.  
  1797. //////////
  1798. //
  1799. // QTFrame_GetFileFilterUPP
  1800. // Return a UPP for the specified file-selection filter function.
  1801. //
  1802. // The caller is responsible for disposing of the UPP returned by this function (by calling DisposeRoutineDescriptor).
  1803. //
  1804. //////////
  1805.  
  1806. QTFrameFileFilterUPP QTFrame_GetFileFilterUPP (ProcPtr theFileFilterProc)
  1807. {
  1808. #if TARGET_OS_MAC
  1809.     return(NewNavObjectFilterUPP((NavObjectFilterProcPtr)theFileFilterProc));
  1810. #endif
  1811. #if TARGET_OS_WIN32
  1812.     return(NewFileFilterProc(theFileFilterProc));
  1813. #endif
  1814. }
  1815.  
  1816.  
  1817. //////////
  1818. //
  1819. // QTFrame_FilterFiles
  1820. // Filter files for a file-opening dialog box.
  1821. //
  1822. // The default behavior here is to accept all files that can be opened by QuickTime, whether directly
  1823. // or using a movie importer or a graphics importer.
  1824. //
  1825. //////////
  1826.  
  1827. #if TARGET_OS_MAC
  1828. PASCAL_RTN Boolean QTFrame_FilterFiles (AEDesc *theItem, void *theInfo, void *theCallBackUD, NavFilterModes theFilterMode)
  1829. {
  1830. #pragma unused(theCallBackUD, theFilterMode)
  1831.     NavFileOrFolderInfo        *myInfo = (NavFileOrFolderInfo *)theInfo;
  1832.     
  1833.     if (gValidFileTypes == NULL)
  1834.         QTFrame_BuildFileTypeList();
  1835.  
  1836.     if (theItem->descriptorType == typeFSS) {
  1837.         if (!myInfo->isFolder) {
  1838.             OSType            myType = myInfo->fileAndFolder.fileInfo.finderInfo.fdType;
  1839.             short            myCount;
  1840.             short            myIndex;
  1841.             
  1842.             // see whether the file type is in the list of file types that our application can open 
  1843.             myCount = GetPtrSize((Ptr)gValidFileTypes) / sizeof(OSType);
  1844.             for (myIndex = 0; myIndex < myCount; myIndex++)
  1845.                 if (myType == gValidFileTypes[myIndex])
  1846.                     return(true);
  1847.  
  1848.             // if we got to here, it's a file we cannot open
  1849.             return(false);        
  1850.         }
  1851.     }
  1852.     
  1853.     // if we got to here, it's a folder or non-HFS object
  1854.     return(true);
  1855. }
  1856. #endif
  1857. #if TARGET_OS_WIN32
  1858. PASCAL_RTN Boolean QTFrame_FilterFiles (CInfoPBPtr thePBPtr)
  1859. {
  1860. #pragma unused(thePBPtr)
  1861.     return(false);
  1862. }
  1863. #endif
  1864.  
  1865.  
  1866. //////////
  1867. //
  1868. // QTFrame_BuildFileTypeList
  1869. // Build a list of file types that QuickTime can open.
  1870. //
  1871. //////////
  1872.  
  1873. OSErr QTFrame_BuildFileTypeList (void)
  1874. {
  1875.     long        myIndex = 0;
  1876.     OSErr        myErr = noErr;
  1877.  
  1878.     // if we've already built the list, just return
  1879.     if (gValidFileTypes != NULL)
  1880.         return(myErr);
  1881.     
  1882.     // allocate a block of memory to hold a preset number of file types; we'll resize this block
  1883.     // while building the list if we need more room; we always resize it after building the list,
  1884.     // to truncate it to the exact size required
  1885.     gValidFileTypes = (OSType *)NewPtrClear(sizeof(OSType) * kDefaultFileTypeCount);
  1886.     if (gValidFileTypes == NULL)
  1887.         return(memFullErr);
  1888.     
  1889.     // we can open any files of type kQTFileTypeMovie
  1890.     gValidFileTypes[myIndex++] = kQTFileTypeMovie;
  1891.     
  1892.     // we can open any files for which QuickTime supplies a movie importer component
  1893.     QTFrame_AddComponentFileTypes(MovieImportType, &myIndex);
  1894.     
  1895.     // we can open any files for which QuickTime supplies a graphics importer component
  1896.     QTFrame_AddComponentFileTypes(GraphicsImporterComponentType, &myIndex);
  1897.  
  1898.     // resize the pointer to hold the exact number of valid file types
  1899.     SetPtrSize((Ptr)gValidFileTypes, myIndex * sizeof(OSType));
  1900.     myErr = MemError();
  1901.     
  1902.     return(myErr);
  1903. }
  1904.  
  1905.  
  1906. //////////
  1907. //
  1908. // QTFrame_AddComponentFileTypes
  1909. // Add all subtypes of the specified component type to the global list of file types.
  1910. //
  1911. //////////
  1912.  
  1913. static void QTFrame_AddComponentFileTypes (OSType theComponentType, long *theNextIndex)
  1914. {
  1915.     ComponentDescription        myFindCompDesc = {0, 0, 0, 0, 0};
  1916.     ComponentDescription        myInfoCompDesc = {0, 0, 0, 0, 0};
  1917.     Component                    myComponent = NULL;
  1918.  
  1919.     myFindCompDesc.componentType = theComponentType;
  1920.     myFindCompDesc.componentFlags = 0;
  1921.     myFindCompDesc.componentFlagsMask = movieImportSubTypeIsFileExtension;
  1922.  
  1923.     myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1924.     while (myComponent != NULL) {
  1925.         GetComponentInfo(myComponent, &myInfoCompDesc, NULL, NULL, NULL);
  1926.         gValidFileTypes[*theNextIndex] = myInfoCompDesc.componentSubType;
  1927.         *theNextIndex += 1;
  1928.         
  1929.         // resize the block of file types, if we are about to reach the limit
  1930.         if (*theNextIndex == GetPtrSize((Ptr)gValidFileTypes) / (long)sizeof(OSType)) {
  1931.             SetPtrSize((Ptr)gValidFileTypes, GetPtrSize((Ptr)gValidFileTypes) + (kDefaultFileTypeCount * sizeof(OSType)));
  1932.             if (MemError() != noErr)
  1933.                 return;
  1934.         }
  1935.         
  1936.         myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1937.     }
  1938. }
  1939.  
  1940.  
  1941. #if TARGET_OS_WIN32
  1942. //////////
  1943. //
  1944. // QTFrame_ConvertMacToWinRect
  1945. // Convert a Macintosh Rect structure into a Windows RECT structure.
  1946. //
  1947. //////////
  1948.  
  1949. void QTFrame_ConvertMacToWinRect (Rect *theMacRect, RECT *theWinRect)
  1950. {
  1951.     theWinRect->top = (long)theMacRect->top;
  1952.     theWinRect->left = (long)theMacRect->left;
  1953.     theWinRect->bottom = (long)theMacRect->bottom;
  1954.     theWinRect->right = (long)theMacRect->right;
  1955. }
  1956.  
  1957.  
  1958. //////////
  1959. //
  1960. // QTFrame_ConvertWinToMacRect
  1961. // Convert a Windows RECT structure into a Macintosh Rect structure.
  1962. //
  1963. //////////
  1964.  
  1965. void QTFrame_ConvertWinToMacRect (RECT *theWinRect, Rect *theMacRect)
  1966. {
  1967.     theMacRect->top = (short)theWinRect->top;
  1968.     theMacRect->left = (short)theWinRect->left;
  1969.     theMacRect->bottom = (short)theWinRect->bottom;
  1970.     theMacRect->right = (short)theWinRect->right;
  1971. }
  1972. #endif
  1973.